using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using ConfiguringApps.Infrastructure;
using Microsoft.Extensions.Configuration;

namespace ConfiguringApps
{
  public class Startup
  {

    public Startup(IConfiguration configuration)
    {
      Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
      services.AddSingleton<UptimeService>();
      services.AddMvc().AddMvcOptions(options => {
        options.RespectBrowserAcceptHeader = true;
      });
    }

    public void ConfigureDevelopmentServices(IServiceCollection services)
    {
      services.AddSingleton<UptimeService>();
      services.AddMvc();
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
      app.UseExceptionHandler("/Home/Error");
      app.UseStaticFiles();
      app.UseMvc(routes => {
        routes.MapRoute(
            name: "default",
            template: "{controller=Home}/{action=Index}/{id?}");
      });
    }

    public void ConfigureDevelopment(IApplicationBuilder app,
            IHostingEnvironment env)
    {
      app.UseDeveloperExceptionPage();
      app.UseStatusCodePages();
      app.UseBrowserLink();
      app.UseStaticFiles();
      app.UseMvcWithDefaultRoute();
    }
  }
}
